package org.come.log;

import org.come.until.MessagrFlagUntil;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
import com.tool.tcpimg.UIUtils;
import java.awt.Container;
import javax.swing.JFrame;
import org.come.init.CheckUpdateJPanel;
import java.awt.event.MouseListener;

public class LanderJFrame implements MouseListener, Runnable
{
    public LanderJPanel landerJPanel;
    private int first_x;
    private int first_y;
    CheckUpdateJPanel checkUpdateJpanel;
    public static JFrame frame;

    public LanderJFrame() {
        LanderJFrame.frame.setResizable(false);
        LanderJFrame.frame.setUndecorated(true);
        this.landerJPanel = new LanderJPanel(this);
        this.checkUpdateJpanel = new CheckUpdateJPanel();
        LanderJFrame.frame.setContentPane((Container)this.landerJPanel);
        LanderJFrame.frame.setBackground(UIUtils.Color_BACK);
        final Toolkit tool = LanderJFrame.frame.getToolkit();
        final Image myimage = tool.getImage("img/icon/ico.png");
        LanderJFrame.frame.setIconImage(myimage);
        LanderJFrame.frame.pack();
        LanderJFrame.frame.setVisible(true);
        LanderJFrame.frame.setLocationRelativeTo(null);
        LanderJFrame.frame.setDefaultCloseOperation(3);
        LanderJFrame.frame.addMouseListener((MouseListener)this);
        LanderJFrame.frame.addMouseMotionListener(new MouseMotionListener() {

            @Override
            public void mouseMoved(final MouseEvent e) {
            }

            @Override
            public void mouseDragged(final MouseEvent e) {
                if (LanderJFrame.frame.isVisible()) {
                    final int x = e.getX() - LanderJFrame.this.first_x;
                    final int y = e.getY() - LanderJFrame.this.first_y;
                    LanderJFrame.frame.setBounds(x + LanderJFrame.frame.getX(), y + LanderJFrame.frame.getY(), LanderJFrame.frame.getWidth(), LanderJFrame.frame.getHeight());
                }
            }

        });
    }

    @Override
    public void run() {
        this.checkUpdateJpanel.getUpdateView().update();
    }

    public LanderJPanel getLanderJPanel() {
        return this.landerJPanel;
    }

    @Override
    public void mouseClicked(final MouseEvent e) {
       // System.out.println("点击");
    }

    @Override
    public void mousePressed(final MouseEvent e) {
        if (e.isMetaDown()) {
            System.exit(0);
        }
        this.first_x = e.getX();
        this.first_y = e.getY();
    }

    @Override
    public void mouseReleased(final MouseEvent e) {
    }

    @Override
    public void mouseEntered(final MouseEvent e) {
    }

    @Override
    public void mouseExited(final MouseEvent e) {
        MessagrFlagUntil.setMouse(MessagrFlagUntil.MOUSE1);
    }

    static {
        frame = new JFrame("游戏窗口");
    }
}
